//1.引入模块
var conn = require("./baseDb.js")

// 向外暴露对象
module.exports = {
    getIndexPageData(callback){ // 获取首页数据
        //输入sql语句查询对应的数据
        //查询文章的数量,草稿状态的文章数量,文章分类数量,评论数量,
        var sql = `select count(*) as postsCount from posts;
     select count(*) as draftedCount from posts where status ='drafted';
     select count(*) as categoriesCount from categories;
     select count(*) as commentsCount from comments;
     select count(*) as heldCount from comments where status='held';`

        //执行sql语句
        conn.query(sql,(err,result)=>{
            if(err) return callback(err)
            callback(null,result) // 返回查询的数据为二维数组对象
        })
    }
}